<template>
	<div class="login-panel">
		<h1 class="title">后台管理系统</h1>
		<el-tabs
			type="border-card"
			class="demo-tabs"
			:stretch="true"
			v-model="currentBar"
		>
			<el-tab-pane name="account">
				<template #label>
					<span class="custom-tabs-label">
						<el-icon><UserFilled /></el-icon>
						<span>账号登录</span>
					</span>
				</template>
				<loginAccount ref="accountRef"></loginAccount>
			</el-tab-pane>
			<el-tab-pane name="phone">
				<template #label>
					<span class="custom-tabs-label">
						<el-icon><PhoneFilled /></el-icon>
						<span>手机登录</span>
					</span>
				</template>
				<loginPhone></loginPhone>
			</el-tab-pane>
		</el-tabs>
		<div class="account-control">
			<el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
			<el-link type="primary">忘记密码</el-link>
		</div>
		<el-button type="primary" class="login-btn" @click="handleLoginClick"
			>立即登录</el-button
		>
	</div>
</template>

<script lang="ts">
	import { defineComponent, ref } from 'vue'

	import loginAccount from './login-account.vue'
	import loginPhone from './login-phone.vue'
	export default defineComponent({
		name: 'LoginPanel',
		components: { loginAccount, loginPhone },
		setup() {
			const isKeepPassword = ref(false)
			//拿到组件对象的类型
			const accountRef = ref<InstanceType<typeof loginAccount>>()
			//区分是手机登录还是账号登录
			const currentBar = ref<string>('account')
			const handleLoginClick = () => {
				// console.log('立即登录')
				if (currentBar.value == 'account') {
					//我是账号登录
					accountRef.value?.loginAction(isKeepPassword.value)
				} else if (currentBar.value == 'phone') {
					// console.log('我是手机登录')
				}
			}
			return {
				isKeepPassword,
				accountRef,
				currentBar,
				handleLoginClick
			}
		}
	})
</script>

<style scoped lang="less">
	.demo-tabs > .el-tabs__content {
		padding: 32px;
		color: #6b778c;
		font-size: 32px;
		font-weight: 600;
	}
	.demo-tabs .custom-tabs-label .el-icon {
		vertical-align: middle;
	}
	.demo-tabs .custom-tabs-label span {
		vertical-align: middle;
		margin-left: 4px;
	}
	.login-panel {
		width: 320px;
		margin-top: -150px;

		.title {
			text-align: center;
		}
		.account-control {
			display: flex;
			justify-content: space-between;
		}
		.login-btn {
			width: 100%;
			margin-top: 10px;
		}
	}
</style>